#pragma once
#include <iostream>
#include <pthread.h>

namespace MutexData
{
	class Mutex
	{
	public:
		Mutex(const Mutex &) = delete;
		Mutex &operator=(const Mutex &) = delete;
		Mutex()
		{
			pthread_mutex_init(&_lock, nullptr);
		}
		void Lock()
		{
			pthread_mutex_lock(&_lock);
		}
		void UnLock()
		{
			pthread_mutex_unlock(&_lock);
		}
		pthread_mutex_t *Mutexptr()
		{
			return &_lock;
		}
		~Mutex()
		{
			pthread_mutex_destroy(&_lock);
		}

	private:
		pthread_mutex_t _lock;
	};

	class LockGuard
	{
	public:
		LockGuard(Mutex &Lock):_mtx(Lock)
		{
			_mtx.Lock();
		}
		~LockGuard()
		{
			_mtx.UnLock();
		}
	private:
		Mutex &_mtx;
    };
}